package com.txy.springcloud.service.dubbo;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.txy.springcloud.service.UserDubboService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

@Service
public class UserServiceImpl implements UserDubboService {

    @Autowired
    private ComboPooledDataSource dataSource;

    @Override
    public String getEmailById(String token) {
        try {
            PreparedStatement preparedStatement = dataSource.getConnection().prepareStatement("select * from user where token = ?");
            preparedStatement.setString(1, token);
            ResultSet resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                return resultSet.getString("email");
            }
            return "";
        }catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
}
